﻿using System;
using System.Collections.Generic;
using System.Text;
using OneMG.Phoenix.Service.Contracts;
using OneMG.Phoenix.Service.Model;
using OneMG.Phoenix.IBatisRepository;
using OneMG.Phoenix.Respository;
using System.Data;
using OneMG.Phoenix.Entity;

namespace OneMG.Phoenix.Service
{
    public class SiteConfigService : ISiteConfigService
    {
		 ISiteConfig siteConfig = new SiteConfigRepository();
		 
        public System.Int32 AddSiteConfig(SiteConfigModel model)
        {
			ESiteConfig entity = ConvertModelToEntity(model);
			
            return siteConfig.AddSiteConfig(entity);
        }

		public void UpdateByConfigID (SiteConfigModel model)
		{
			ESiteConfig entity = ConvertModelToEntity(model);

            siteConfig.UpdateByConfigID(entity);

		}

		public void DeleteByConfigID (System.Int32 configID)
		{
		
            siteConfig.DeleteByConfigID(configID);

		}
		 
        public SiteConfigModel GetByConfigID (System.Int32 configID)
        {
        
			ESiteConfig entity = siteConfig.GetByConfigID(configID);
			
            SiteConfigModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public SiteConfigModel ConvertEntityToModel(ESiteConfig entity)
		{
			if (entity == null)
            {
                return null;
            }
			SiteConfigModel model = new SiteConfigModel();
                        model.ConfigID = entity.ConfigID;
                        model.SiteName = entity.SiteName;
                        model.SiteUrl = entity.SiteUrl;
                        model.SiteCert = entity.SiteCert;
                        model.SiteCopyRight = entity.SiteCopyRight;
                        model.SiteBuildTime = entity.SiteBuildTime;
                        model.SiteDescription = entity.SiteDescription;
                        model.SiteKeyWord = entity.SiteKeyWord;
                        model.SiteAddress = entity.SiteAddress;
                        model.SiteTel = entity.SiteTel;
                        model.SiteEmail = entity.SiteEmail;
                        model.SiteMasterStat = entity.SiteMasterStat;
                        model.About = entity.About;
                        model.ContactInfo = entity.ContactInfo;
                        return model;
		}
		
		public ESiteConfig ConvertModelToEntity(SiteConfigModel model)
		{
			if (model == null)
            {
                return null;
            }
			ESiteConfig entity = new ESiteConfig();
                        entity.ConfigID = model.ConfigID;
                        entity.SiteName = model.SiteName;
                        entity.SiteUrl = model.SiteUrl;
                        entity.SiteCert = model.SiteCert;
                        entity.SiteCopyRight = model.SiteCopyRight;
                        entity.SiteBuildTime = model.SiteBuildTime;
                        entity.SiteDescription = model.SiteDescription;
                        entity.SiteKeyWord = model.SiteKeyWord;
                        entity.SiteAddress = model.SiteAddress;
                        entity.SiteTel = model.SiteTel;
                        entity.SiteEmail = model.SiteEmail;
                        entity.SiteMasterStat = model.SiteMasterStat;
                        entity.About = model.About;
                        entity.ContactInfo = model.ContactInfo;
                        return entity;
		}
    }
}